package com.mes.basicdata.domain;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas;
import org.hibernate.annotations.JoinFormula;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.springframework.context.annotation.Lazy;

import com.bstek.bdf2.core.model.DefaultDept;
import com.mes.common.domain.BasicModel;

@Entity()
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name = "R_DEPT")
@BatchSize(size=10)
@Lazy(value=true)
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Dept extends BasicModel implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	@Id
	@GenericGenerator(name = "deptId", strategy = "assigned")
	@Column(name="DEPTID",length=50)
	private String deptUid;
	
	@Column(name="DEPTNAME",length=50)
	private String deptName;
	
	// 部门领导
	@Column(name="LEADERID",length=50)
	private String leaderId;
	
	// 部门联系人
	@Column(name="CONTACTID",length=50)
	private String contactId;
	
	// 部门类型
	@Column(name="DEPTTYPE",length=50)
	private String deptType;
	
	// 父部门
	@Column(name="SUPERDEPTID",length=50)
	private String parentDeptUid;
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@Fetch(FetchMode.SELECT)
	@JoinColumn(name="SUPERDEPTID",insertable=false,updatable=false)
	private Dept parentDept;
	
	// 子部门
	@OneToMany(fetch=FetchType.LAZY)
	@JoinColumn(name="SUPERDEPTID")
	private List<Dept> childDepts;
	
	//BDF部门
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="BDFDEPT")
	private DefaultDept BDFDept;
	
	
	@Override
	public String getUuid() {
		// TODO Auto-generated method stub
		return this.getDeptUid();
	}

	@Override
	public void setUuid(String uuid) {
		// TODO Auto-generated method stub
		this.setDeptUid(uuid);
	}
	
	public List<Dept> getChildDepts() {
		return childDepts;
	}
	public void setChildDepts(List<Dept> childDepts) {
		this.childDepts = childDepts;
	}
	@Column(name="SCHEMAID",length=50)
	private String deptShortName;
	
	@Column(name="CUSTOMER_DEPTID",length=50)
	private String customerDeptId;
	
	//many-to-one
	/*@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumnsOrFormulas(value={
			@JoinColumnOrFormula(column=@JoinColumn(name="DEPT_LEVEL",referencedColumnName="ID",nullable=true,insertable=false,updatable=false)),
			@JoinColumnOrFormula(formula=@JoinFormula(value="'deptleveltype'", referencedColumnName="TYPESNAME"))
	})
	@NotFound(action=NotFoundAction.IGNORE)
	private TypesData deptLevelTypeDesc;*/
	
	@Column(name="DEPT_LEVEL",length=50)	
	private String deptLevel;
	
	@Column(name="DEPT_TREE_CODE",length=50)
	protected String deptTreeCode;
	
	public String getDeptUid() {
		return deptUid;
	}
	public void setDeptUid(String deptUid) {
		this.deptUid = deptUid;
	}
	
	public String getLeaderId() {
		return leaderId;
	}
	public void setLeaderId(String leaderId) {
		this.leaderId = leaderId;
	}
	public String getDeptName() {
		return deptName;
	}
	public void setDeptName(String deptName) {
		this.deptName = deptName;
	}
	
	public String getContactId() {
		return contactId;
	}
	public void setContactId(String contactId) {
		this.contactId = contactId;
	}	
	public String getCreatorUid() {
	return creatorUid;
	}
	public void setCreatorUid(String creatorUid) {
		this.creatorUid = creatorUid;
	}
	public String getDeptType() {
		return deptType;
	}
	public void setDeptType(String deptType) {
		this.deptType = deptType;
	}
	public Dept getParentDept() {
		return parentDept;
	}
	public void setParentDept(Dept parentDept) {
		this.parentDept = parentDept;
	}
	public String getParentDeptUid() {
		return parentDeptUid;
	}
	public void setParentDeptUid(String parentDeptUid) {
		this.parentDeptUid = parentDeptUid;
	}
	public String getDeptShortName() {
		return deptShortName;
	}
	public void setDeptShortName(String deptShortName) {
		this.deptShortName = deptShortName;
	}
	public String getCustomerDeptId() {
		return customerDeptId;
	}
	public void setCustomerDeptId(String customerDeptId) {
		this.customerDeptId = customerDeptId;
	}
	/*public TypesData getDeptLevelTypeDesc() {
		return deptLevelTypeDesc;
	}
	public void setDeptLevelTypeDesc(TypesData deptLevelTypeDesc) {
		this.deptLevelTypeDesc = deptLevelTypeDesc;
	}*/
	public String getDeptLevel() {
		return deptLevel;
	}
	public void setDeptLevel(String deptLevel) {
		this.deptLevel = deptLevel;
	}
	public String getDeptTreeCode() {
		return deptTreeCode;
	}
	public void setDeptTreeCode(String deptTreeCode) {
		this.deptTreeCode = deptTreeCode;
	}

	public DefaultDept getBDFDept() {
		return BDFDept;
	}

	public void setBDFDept(DefaultDept bDFDept) {
		BDFDept = bDFDept;
	}
	
}